<template>
  <div class="app-container">
    <el-form :model="form" class="demo-form-inline">
      <el-form-item label="">
        <el-input v-model="form.name" placeholder="请输入公寓名称" style="width: 200px" />
      </el-form-item>

      <el-form-item label="">
        <el-date-picker v-model="form.t1" type="date" placeholder="开始时间" style="width: 200px;" />
        <el-date-picker v-model="form.t2" type="date" placeholder="结束时间" style="width: 200px;" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="warning" plain @click="empty">清空</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="tableData"
      style="width: 100%"
    >
      <el-table-column
        prop="factoringOrderNo"
        label="申请合同号"
        width="180"
      />
      <el-table-column
        prop="na"
        label="大众公寓"
        width="180"
      />
      <el-table-column
        prop="rootName"
        label="承租房间"
      />
      <el-table-column
        prop="tenantName"
        label="租客姓名"
      />
      <el-table-column
        prop="shouldMonthRent"
        label="应还保理租金"
      />
      <el-table-column
        label="账期"
      >
        <template scope="scope">
          {{ scope.row.borrowedStart }}-{{ scope.row.borrowedEnd }}
        </template>
      </el-table-column>
      <el-table-column
        prop="collectionDate"
        label="交租日期"
      />
      <el-table-column
        prop="capitalName"
        label="资金方"
      />
    </el-table>
    <el-pagination
      :current-page="form.pageNum"
      :page-sizes="[10,12,15,20]"
      :page-size="form.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      total: null,
      form: {
        pageNum: null,
        pageSize: null,
        name: '',
        t1: '',
        t2: ''
      }
    }
  },
  created() {
    this.init()
  },
  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.form.pageSize = val
      this.init()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.form.pageNum = val
      this.init()
    },
    init() {
      this.axios.get('http://127.0.0.1/api/cw/wish/t-jr-factoring-detail/list', { params: this.form }).then((response) => {
        this.tableData = response.data.obj.list
        this.form.pageNum = response.data.obj.pageNum
        this.form.pageSize = response.data.obj.pageSize
        this.total = response.data.obj.total
      })
    },
    empty() {
      this.form.name = ''
    },
    onSubmit() {
      this.init()
    }
  }
}
</script>
